package com.yeyks.task;

import com.yeyks.other.dal.domain.ImportCityDataConfig;
import com.yeyks.other.service.ImportCityDataConfigService;
import com.yeyks.search.service.hotel.EsImportHotelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * cn 数据导入
 * @author: dagny
 * @date: 2019/11/7 0007 13:58
 */
@Component
@Slf4j
public class CnImportTask {

    @Autowired
    private ImportCityDataConfigService importCityDataConfigService;

    @Autowired
    private EsImportHotelService esImportHotelService;

    /*@Scheduled(cron = "${schedule.hotel.esData}")*/
    public void importHotelInEs(){

        log.info("开始执行导入数据");
        //查询导入城市的集合
        List<ImportCityDataConfig> list = importCityDataConfigService.list();

        if(!CollectionUtils.isEmpty(list)){
            for (ImportCityDataConfig importCityDataConfig : list){
                //执行数据导入
                esImportHotelService.importCnBookingHotelByPage("index_hotel","0001",
                        importCityDataConfig.getProvinceId(), importCityDataConfig.getCityId(),
                        20,1);

                log.info(importCityDataConfig.getProvinceName()+"的：" + importCityDataConfig.getCityName() + "导入成功！");
            }
        }


    }

}
